package com.sdhs.workflow.controller;

import com.sdhs.common.core.controller.BaseController;
import com.sdhs.common.core.domain.R;
import com.sdhs.workflow.domain.UnifyPushLog;
import com.sdhs.workflow.domain.vo.UnifyTaskVo;
import com.sdhs.workflow.service.IUnifyPushLogService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/Iaw/portal/api")
public class TestSTKController extends BaseController {

    @Autowired(required = false)
    private IUnifyPushLogService iUnifyPushLogService;

    @PostMapping("/wfms/pushTodo")
    public Map<String,Object> addTask(HttpServletRequest request,@RequestBody UnifyTaskVo taskVo)
    {
        String ClientId = request.getHeader("ClientId");
        String OperationCode = request.getHeader("OperationCode");

        Map<String,String> headers = new HashMap<>();
        headers.put("OperationCode",OperationCode);
        headers.put("ClientId",ClientId);

        Map<String,Object> res = new HashMap<>();
        res.put("headers",headers);
        res.put("data",taskVo);

        Map<String,Object> map = new HashMap<>();
        map.put("success",true);
        map.put("code","0000");
        map.put("message","success");
        map.put("dataId","add");

        return map;
    }

    @PostMapping("/wfms/deleteTodo")
    public Map<String,Object> deleteTodo(HttpServletRequest request,@RequestBody UnifyTaskVo taskVo)
    {
        String ClientId = request.getHeader("ClientId");
        String OperationCode = request.getHeader("OperationCode");

        Map<String,String> headers = new HashMap<>();
        headers.put("OperationCode",OperationCode);
        headers.put("ClientId",ClientId);

        Map<String,Object> res = new HashMap<>();
        res.put("headers",headers);
        res.put("data",taskVo);

        Map<String,Object> map = new HashMap<>();
        map.put("success",true);
        map.put("code","0000");
        map.put("message","success");
        map.put("dataId","del");

        return map;
    }

    @PostMapping("/wfms/setDone")
    public Map<String,Object> setDone(HttpServletRequest request,@RequestBody UnifyTaskVo taskVo)
    {
        String ClientId = request.getHeader("ClientId");
        String OperationCode = request.getHeader("OperationCode");

        Map<String,String> headers = new HashMap<>();
        headers.put("OperationCode",OperationCode);
        headers.put("ClientId",ClientId);

        Map<String,Object> res = new HashMap<>();
        res.put("headers",headers);
        res.put("data",taskVo);

        Map<String,Object> map = new HashMap<>();
        map.put("success",true);
        map.put("code","0000");
        map.put("message","success");
        map.put("dataId","set");

        return map;
    }

    @PostMapping("/mms/sendMsg")
    public Map<String,Object> sendMsg(HttpServletRequest request,@RequestBody UnifyTaskVo taskVo)
    {
        String ClientId = request.getHeader("ClientId");
        String OperationCode = request.getHeader("OperationCode");

        Map<String,String> headers = new HashMap<>();
        headers.put("OperationCode",OperationCode);
        headers.put("ClientId",ClientId);

        Map<String,Object> res = new HashMap<>();
        res.put("headers",headers);
        res.put("data",taskVo);

        Map<String,Object> map = new HashMap<>();
        map.put("success",true);
        map.put("code","0000");
        map.put("message","success");
        map.put("dataId","WXWORK");

        return map;
    }

    @PostMapping("/test")
    public R test(@RequestBody UnifyPushLog log)
    {
//        String res = iUnifyApiService.pushTodo(request.getHeader("ClientId"),request.getHeader("OperationCode"),taskVo);
//        UnifyApiUtils.push2Unify("add",null,"单据审批流程",null);
//        UnifyApiUtils.push2Unify("del",null,"单据审批流程",null);
//        UnifyApiUtils.push2Unify("set",null,"单据审批流程",null);
//        UnifyApiUtils.push2Unify("WXWORK",null,"单据审批流程",null);

        iUnifyPushLogService.insert(log);
        return R.ok();
    }

}
